home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / man / Basics.tex < prev    next >
Encoding:
Text File  |  1994-08-05  |  24.9 KB  |  600 lines

  1. {\magtwo 1. Basics}
  2.  
  3. {\magonebf 1.1 A First Example}
  4.  
  5. The following program can be compiled and linked 
  6. with LEDA's basic library $libL.a$ (cf.~section~1.10).
  7. When executed it reads a sequence of strings from the standard input and then 
  8. prints the number of occurrences of each string on the standard output. More 
  9. examples of LEDA programs can be found throughout this manual.
  10.  
  11. \bigskip
  12. \#include \<LEDA/d\_array.h\>
  13. \medskip
  14. \cleartabs
  15. \+main()\cr
  16. \+$\{$\ \ &\cr
  17. \+        &d\_array\<string,int\> $N(0)$;\cr
  18. \smallskip
  19. \+        &string $s$;\cr
  20. \smallskip
  21. \+        &{\bf while} &(cin \>\> $s$ ) $N[s]${\tt ++};\cr
  22. \smallskip
  23. \+        &{\bf forall\_defined}($s,N$) 
  24.                 cout \<\< $s$ \<\< " " \<\< $N[s]$ \<\< $endl$;\cr
  25. \smallskip
  26. \+\ $\}$\cr
  27. \bigskip
  28.  
  29.  
  30. The program above uses the parameterized data type dictionary array 
  31. ($d\_array\<I,E\>$) from the library. This is expressed by the include 
  32. statement (cf.~section~1.9 for more details). The specification of the 
  33. data type $d\_array$ can be found in section~4.4. We use it also as a 
  34. running example to discuss the principles underlying LEDA in sections 1.2 
  35. to 1.10.
  36.  
  37. Parameterized data types in LEDA are realized by templates,
  38. inheritance and dynamic binding (see [N92] for details).
  39. For \CC compilers not supporting templates there is still available a 
  40. non-template version of LEDA using declare macros as described in [N90].
  41.  
  42.  
  43. \bigskip
  44. {\magonebf 1.2 Specifications}
  45.  
  46. In general the specification of a LEDA data type consists of four parts:
  47. a definition of the set of objects comprising the (parameterized) abstract
  48. data type, a description of how to create an object of the data type,
  49. the definition of the operations available on the objects of the data 
  50. type, and finally, information about the implementation. The four parts 
  51. appear under the headers definition, creation, operations, and implementation 
  52. respectively.
  53.  
  54. \bigskip
  55. $\bullet$ {\bf Definition}
  56. \smallskip
  57. This part of the specification defines the objects (also called instances or
  58. elements) comprising the data type using standard mathematical concepts and 
  59. notation. 
  60.  
  61. {\bf Example}, the generic data type dictionary array:
  62.  
  63. An object $a$ of type $d\_array\<I,E\>$ is an injective function from the
  64. data type $I$ to the set of variables of data type $E$. The types $I$ and
  65. $E$ are called the index and the element type respectively, $a$ is called
  66. a dictionary array from $I$ to $E$.
  67.  
  68. Note that the types $I$ and $E$ are parameters in the definition above.
  69. Any built-in, pointer, item, or user-defined class type $T$ can be used 
  70. as actual type parameter of a parameterized data type. Class types however 
  71. have to provide the following operations:
  72. \medskip
  73. \+\cleartabs
  74.   a) &a constructor taking no arguments \quad  
  75.                             &T::T() \cr
  76. \+b) &a copy constructor    &T::T(const T\&) \cr
  77. \+c) &an input function     &void \ {\bf Read}(T\&,\ istream\&)\cr
  78. \+d) &an output function    &void \ {\bf Print}(const T\&,\ ostream\&)\cr
  79.  
  80. A compare function ``int {\bf compare}(const T\&, const T\&)" (cf.~section~1.6)
  81. has to be defined if the data type requires that $T$ is linearly ordered.
  82. Section~1.4 contains a complete example.
  83.  
  84. \bigskip
  85. $\bullet$ {\bf Creation}
  86. \smallskip
  87. A variable of a data type is introduced by a \CC variable declaration. 
  88. For all LEDA data types variables are initialized at the time of declaration. 
  89. In many cases the user has to provide arguments used for the initialization 
  90. of the variable.  In general a declaration
  91.  
  92. $XYZ\<t_1,\dots,t_k\>$ \ \ \ $y(x_1,\dots,x_\ell)$;
  93.  
  94. introduces a variable $y$ of the data type ``$XYZ\<t_1,\dots,t_k\>$''
  95. and uses the arguments $x_1,\dots,x_\ell$ to initialize it. For example,
  96.  
  97. $d\_array\<string,int\>$ $A(0)$
  98.  
  99. introduces $A$ as a dictionary array from strings to integers, and 
  100. initializes $A$ as follows: an injective function $a$ from $string$
  101. to the set of unused variables of type $int$ is constructed, and is
  102. assigned to $A$. Moreover, all variables in the range of $a$ are 
  103. initialized to 0.
  104. The reader may wonder how LEDA handles an array of infinite size. The
  105. solution is, of course, that only that part of $A$ is explicitly stored
  106. which has been accessed already.
  107.  
  108. For all data types, the assignment operator ($=$) is available for variables 
  109. of that type. Note however that assignment is in general not a constant time 
  110. operation, e.g., if $L_1$ and $L_2$ are variables of type $list\<T\>$ then the 
  111. assignment $L_1 = L_2$ takes time proportional to the length of the list $L_2$
  112. times the time required for copying an object of type $T$.
  113.  
  114. {\bf Remark}: For most of the complex data types of LEDA, e.g., dictionaries,
  115. lists, and priority queues, it is convenient to interpret a variable name
  116. as the name for an object of the data type which evolves over time by means
  117. of the operations applied to it. This is appropriate, whenever the operations 
  118. on a data type only ``modify'' the values of variables, e.g., it is more 
  119. natural to say an operation on a dictionary $D$ modifies $D$ than to say that 
  120. it takes the old value of $D$, constructs a new dictionary out of it, and 
  121. assigns the new value to $D$. Of course, both interpretations are equivalent.
  122. From this more object-oriented point of view, a variable declaration, e.g.,
  123. $dictionary\<string,int\>$ $D$, is creating a new dictionary object with 
  124. name $D$ rather than introducing a new variable of type 
  125. $dictionary\<string,int\>$; hence the name ``creation'' for this part of 
  126. a specification.
  127.  
  128.  
  129.  
  130. \bigskip
  131. $\bullet$ {\bf Operations}
  132. \smallskip
  133. In this section the operations of the data types are described. For each 
  134. operation the description consists of two parts
  135.  
  136. \beginitem
  137. \item {a)}
  138. {The interface of the operation is defined using the \CC function declaration
  139. syntax. In this syntax the result type of the operation ($void$ if there is 
  140. no result) is followed by the operation name and an argument list specifying 
  141. the type of each argument. For example,}
  142. \item{}
  143. {$list\_item$ $L$.insert ($E\ x,\ list\_item\ it,\ rel\_pos\ p=after$)\nl
  144. defines the interface of the insert operation on a list $L$ of elements of type
  145. $E$ (cf.~section~3.7). Insert takes as arguments an element $x$ of type $E$, 
  146. a $list\_item$ $it$ and an optional relative position argument $p$. It returns 
  147. a $list\_item$ as result.  }
  148. \item{}
  149. {$E\&$  $A[I\ x]$\nl
  150. defines the interface of the access operation on a dictionary array $A$. It 
  151. takes an element of $I$ as an argument and returns a variable of type $E$.
  152. }
  153.  
  154. \bigskip
  155. \item {b)} 
  156. {The effect of the operation is defined.  Often the arguments have to 
  157. fulfill certain preconditions. If such a condition is violated the effect 
  158. of the operation is undefined. Some, but not all, of these cases result 
  159. in error messages and abnormal termination of the program (see also 
  160. section~7.5). For the insert operation on lists this definition reads:\nl
  161.  A new item with contents $x$ is inserted after (if $p=after$) or before 
  162. (if $p=before$) item $it$ into $L$. The new item is returned.
  163. ({\it precondition}: item $it$ must be in $L$)}
  164. \item{}
  165. {For the access operation on dictionary arrays the definition reads:\nl
  166. returns the variable $A(x)$.
  167. }
  168. \enditem
  169.  
  170. \bigskip
  171. $\bullet$ {\bf  Implementation}
  172. \smallskip
  173. The implementation section lists the (default) data structures used to 
  174. implement the data type and gives the time bounds for the operations and 
  175. the space requirement. For example,
  176.  
  177. Dictionary arrays are implemented by randomized search trees ([AS89]). 
  178. Access operations $A[x]$ take time $O(\log dom(A))$.
  179. The space requirement is $O(dom(A))$.
  180.  
  181. \bigskip
  182. {\magonebf 1.3 Implementation Parameters}
  183.    
  184. For many of the parameterized data types (in the current version: dictionary, 
  185. priority queue, d\_array, and sortseq) there exist variants taking an additional
  186. data structure parameter for choosing a particular implementation 
  187. (cf.~section~4). Since \CC does not allow to overload templates we had 
  188. to use different names: the variants with an additional implementation 
  189. parameters start with an underscore, e.g., \_d\_array\<I,E,impl\>. 
  190. We can easily modify the example program from section~1.1 to use a dictionary 
  191. array implemented by a particular data structure, e.g., skip lists ([Pu89]), 
  192. instead of the default data structure (cf. section~4.4.5).
  193. \medskip
  194. \cleartabs
  195. \+\#include \<LEDA/d\_array.h\>\cr
  196. \+\#include \<LEDA/impl/skiplist.h\>\cr
  197. \smallskip
  198. \+main()\cr
  199. \+$\{$\ \ &\_d\_array\<string,int,skiplist\> $N(0)$;\cr
  200. \smallskip
  201. \+        &string $s$;\cr
  202. \smallskip
  203. \+        &{\bf while} &(cin \>\> $s$ ) $N[s]${\tt ++};\cr
  204. \smallskip
  205. \+        &{\bf forall\_defined}($s,N$) 
  206.                 cout \<\< $s$ \<\< " " \<\< $N[s]$ \<\< $endl$;\cr
  207. \smallskip
  208. \+\ $\}$\cr
  209.  
  210. Any type \_XYZ\<$T_1,\dots,T_k,xyz\_impl$\> is derived from the corresponding
  211. ``normal" parameterized type XYZ\<$T_1,\dots,T_k$\>, i.e., an instance of type 
  212. \_XYZ\<$T_1,\dots,T_k,xyz\_impl$\> can be passed as argument to functions with
  213. a formal parameter of type XYZ\<$T_1,\dots,T_k$\>\&. 
  214. This provides a mechanism
  215. for choosing implementations of data types in pre-compiled algorithms.
  216. See ``prog/graph/dijkstra.c" for an example.
  217.  
  218. LEDA offers several implementations for each of the data types. For
  219. instance, skip lists, randomized search trees, and red-black trees
  220. for dictionary arrays. Users can also provide their own implementation. 
  221. A data structure ``xyz\_impl" can be used as actual
  222. implementation parameter for a data type $\_XYZ$ if it provides a 
  223. certain set of operations and uses certain virtual functions for type 
  224. dependent operations (e.g. compare, initialize, copy, \dots).
  225. Section~9 lists all data structures contained in the current version and 
  226. gives the exact requirements for implementations of 
  227. dictionaries, priority\_queues, sorted sequences and dictionary arrays.
  228. A detailed description of the mechanism for parameterized data types and 
  229. implementation parameters used in LEDA can be found in [N92].
  230.  
  231.  
  232. \bigskip
  233. {\magonebf 1.4 Arguments}
  234.  
  235. \bigskip
  236. $\bullet$ {\bf Optional Arguments}
  237. \smallskip
  238. The trailing arguments in the argument list of an operation may be optional.
  239. If these trailing arguments are missing in a call of an operation the default 
  240. argument values given in the specification are used. For
  241. example, if the relative position argument in the list insert operation
  242. is missing it is assumed to have the value $after$, i.e.,
  243. $L$.insert($it,y$) will insert the item \<$y$\> after item $it$ into $L$.
  244.  
  245. \bigskip
  246. $\bullet$ {\bf Argument Passing}
  247. \smallskip
  248. There are two kinds of argument passing in \CC, by value and by reference.
  249. An argument $x$  of type $type$  specified by ``$type\ x$'' in the argument 
  250. list of an operation or user defined function will be passed by value, i.e.,
  251. the operation or function is provided with a copy of $x$.
  252. The syntax for specifying an argument passed by reference is ``$type\&\ x$''.
  253. In this case the operation or function works directly on $x$ ( the variable
  254. $x$ is passed not its value).
  255.  
  256. Passing by reference must always be used if the operation is to change the
  257. value of the argument. It should always be used for passing large objects
  258. such as lists, arrays, graphs and other LEDA data types to functions.
  259. Otherwise a complete copy of the actual argument is made, which takes time
  260. proportional to its size, whereas  passing by reference always takes constant
  261. time. 
  262.  
  263.  
  264. \bigskip
  265. $\bullet$ {\bf Functions as Arguments}
  266. \smallskip
  267. Some operations take functions as arguments. For instance the bucket sort 
  268. operation on lists requires a function which maps the elements of the list into
  269. an interval of integers. We use the \CC syntax to define the type of a function
  270. argument $f$:
  271. $$T\ \ (*f)(T_1, T_2,\dots, T_k)$$ declares $f$ to be a function 
  272. taking $k$ arguments of the data types $T_1$, \dots, $T_k$,
  273. respectively, and returning a result of type $T$, i.e,
  274. $f: T_1 \times \dots \times T_k \longrightarrow T$ .
  275.  
  276.  
  277. \bigskip
  278. {\magonebf 1.5 Overloading}
  279.  
  280. Operation and function names may be overloaded, i.e., there can be different 
  281. interfaces for the same operation. An example is the translate operations
  282. for points (cf.~section~6.1).
  283. \smallskip
  284. $point$  $p$.translate($vector\ v$)\nl
  285. $point$  $p$.translate($double\ \alpha,\ double\ dist$)
  286.  
  287. It can either be called with a vector as argument or with two arguments
  288. of type $double$ specifying the direction and the distance of the translation.
  289.  
  290. An important overloaded function is discussed in the next section: Function 
  291. $compare$, used to define linear orders for data types.
  292.  
  293. \bigskip
  294. {\magonebf 1.6 Linear Orders}
  295.  
  296. Many data types, such as dictionaries, priority queues, and sorted sequences
  297. require linearly ordered subtypes. Whenever a type $T$ is used in such a
  298. situation, e.g. in $dictionary\<T,\dots\>$ the function
  299. $$int\ \ compare(T,T)$$ must be declared and must define a linear order on
  300. the data type $T$.
  301.  
  302. A binary relation $rel$ on a set $T$ is called a linear order on $T$ if for
  303. all $x,y,z\in T$:
  304. \smallskip
  305. 1) $x$ $rel$ $y$\nl
  306. 2) $x$ $rel$ $y$ and $y$ $rel$ $z$ implies $x$ $rel$ $z$\nl
  307. 3) $x$ $rel$ $y$ or  $y$ $rel$ $x$\nl
  308. 4) $x$ $rel$ $y$ and $y$ $rel$ $x$ implies $x = y$
  309.  
  310. \medskip
  311. A function $int$ $compare(T,T)$ is said to define the linear order 
  312. $rel$ on $T$ if
  313. $$compare(x,y)\ \ \cases{ < 0, &if $x$ $rel$ $y$  and  $x\ne y$\cr 
  314.                        = 0, &if $x = y$\cr 
  315.                        > 0, &if $y$ $rel$ $x$  and  $x\ne y$\cr} $$
  316.  
  317.  
  318. For each of the simple data types $char$, $short$, $int$, $long$, $float$, 
  319. $double$, $string$, and $point$ a function $compare$ is predefined and defines 
  320. the so-called default ordering on that type. The default ordering is the 
  321. usual $\le$ - order for the built-in numerical types, the lexicographic 
  322. ordering for $string$, and for $point$ the lexicographic ordering of the 
  323. cartesian coordinates.  For all other types $T$ there is no default 
  324. ordering, and the user has to provide a $compare$ function whenever a linear 
  325. order on $T$ is required.
  326.  
  327.  
  328.  
  329. {\bf Example}: Suppose pairs of real numbers shall be used as keys 
  330. in a dictionary with the lexicographic order of their components.
  331. First we declare class $pair$ as the type of pairs of real numbers, 
  332. then we define the I/O operations $Read$ and $Print$ and the 
  333. lexicographic order on $pair$ by writing an appropriate $compare$ function.
  334.  
  335.  
  336. \bigskip
  337. \cleartabs
  338. \+{\bf class} $pair$ $\{$\cr
  339. \+\quad &$double\ \ x$;\cr
  340. \+      &$double\ \ y$;\cr
  341. \+\cr
  342. \+&$pair()\ \{\ x = y = 0;\ \}$\cr
  343. \+&$pair($const $pair\&\ p)\ \{\ x = p.x;\ y = p.y;\ \}$\cr
  344. \+\cr
  345. \+&friend $void$   &Read($pair$\&\ $p$, $istream$\&\ $is$)
  346.            $\{$ $is$ \>\> $p.x$ \>\> $p.y$; $\}$\cr
  347. \+&friend $void$ \ &Print(const $pair$\&\ $p$, $ostream$\& $os$) 
  348.            $\{$ $os$ \<\< $p.x$ \<\< `` " \<\< $p.y$; $\}$\cr
  349. \+&friend $int$    &compare(const $pair$\&, const $pair$\&);\cr
  350. \+$\}$;\cr
  351. \+\cleartabs\cr
  352. \+$int$\  \ \ compare(const $pair\&\ p$, const $pair\&\ q$)\cr
  353. \+$\{$\ \ &{\bf if} ($p.x$ \< $q.x$) {\bf return } -&1;\cr 
  354. \+        &{\bf if} ($p.x$ \> $q.x$) {\bf return }  &1;\cr 
  355. \+        &{\bf if} ($p.y$ \< $q.y$) {\bf return } -&1;\cr 
  356. \+        &{\bf if} ($p.y$ \> $q.y$) {\bf return }  &1;\cr 
  357. \+        &{\bf return} 0; \ $\}$\cr
  358.  
  359. Now we can use dictionaries with key type $pair$, e.g.,
  360.  
  361. dictionary\<$pair$,$int$\> D;
  362.  
  363. \bigskip
  364. Sometimes, a user may need additional linear orders on a data type $T$ 
  365. which are different from the order defined by $compare$, e.g., he might 
  366. want to order points in the plane by the lexicographic ordering of their 
  367. cartesian coordinates and by their polar coordinates. In this example, the 
  368. former ordering is the default ordering for points. The user can introduce 
  369. an alternative ordering on the data type $point$ (cf.~section 6.1) by defining 
  370. an appropriate comparing function $int$ $cmp$(const $point$\&, const $point$\&)
  371. and then calling the macro DEFINE\_LINEAR\_ORDER($point$, $cmp$, $point_1$). 
  372. After this call $point_1$ is a new data type which is equivalent to the data 
  373. type $point$, with the only exception that if $point_1$ is used as an actual 
  374. parameter e.g. in $dictionary\<point_1,\dots\>$, the resulting data type 
  375. is based on the linear order defined by $cmp$.
  376.  
  377. In general the macro call
  378. \smallskip
  379. \quad\quad\quad DEFINE\_LINEAR\_ORDER($T$,$cmp$,$T_1$)  
  380. \smallskip
  381. introduces a new type $T_1$ equivalent to type $T$ with the linear order
  382. defined by the compare function $cmp$.
  383.  
  384. In the example, we first declare a function $pol\_cmp$ and derive a new type
  385. $pol\_point$ using the DEFINE\_LINEAR\_ORDER macro.
  386. \smallskip
  387. \+$int$  $pol\_cmp$(const $point$\& $x$, cosnt $point$\&\ $y$)\cr
  388. \+$\{$\ \ \co lexicographic ordering on polar coordinates  $\}$\cr
  389. \+\cr
  390. \+DEFINE\_LINEAR\_ORDER($point$,$pol\_cmp$,$pol\_point$)\cr
  391.  
  392. Now, dictionaries based on either ordering can be used.
  393. \medskip
  394. \cleartabs
  395. \+$dictionary\<pol\_point,int\>$ $D_1$; \quad &\co polar ordering\cr
  396. \smallskip
  397. \+$dictionary\<point,int\>$ $D_0$;            &\co default ordering\cr
  398. \bigskip
  399.  
  400. {\bf Remark}: We have chosen to associate a fixed linear order with most of
  401. the simple types (by predefining the function $compare$). This order is used
  402. whenever operations require a linear order on the type, e.g., the operations
  403. on a dictionary. Alternatively, we could have required the user to specify a
  404. linear order each time he uses a simple type in a situation where an ordering
  405. is needed, e.g., a user could define
  406.  
  407. \quad\quad\quad $dictionary\<point,lexicographic\_ordering,\dots\>$
  408.  
  409. This alternative would handle the cases where two or more different orderings
  410. are needed more elegantly. However, we have chosen the first alternative
  411. because of the smaller implementation effort.
  412.  
  413.  
  414. \bigskip
  415. {\magonebf 1.7 Items }
  416.  
  417. Many of the advanced data types in LEDA (e.g. dictionaries), are defined in
  418. terms of so-called items. An item is a container which can hold an object
  419. relevant for the data type. For example, in the case of dictionaries a
  420. $dic\_item$ contains a pair consisting of a key and an information.
  421. A general definition of items will be given at the end of this section. 
  422.  
  423. We now discuss the role of items for the dictionary example in some detail. 
  424. A popular specification of dictionaries defines a dictionary as a partial
  425. function from some type $K$ to some other type $I$, or alternatively, as a
  426. set of pairs from $K\times I$, i.e., as the graph of the function. In an
  427. implementation each pair $(k,i)$ in the dictionary is stored in some location
  428. of the memory. Efficiency dictates that the pair $(k,i)$ cannot only be
  429. accessed through the key $k$ but sometimes also through the location where it
  430. is stored, e.g., we might want to lookup the information $i$ associated with
  431. key $k$ (this involves a search in the data structure), then compute with the
  432. value $i$ a new value $i\'$, and finally associate the new value with $k$.
  433. This either involves another search in the data structure or, if the lookup
  434. returned the location where the pair $(k,i)$ is stored, can be done by direct
  435. access. Of course, the second solution is more efficient and we therefore
  436. wanted to provide it in LEDA.
  437.  
  438. In LEDA items play the role of positions or locations in data structures. Thus
  439. an object of type $dictionary\<K,I\>$, where $K$ and $I$ are types, is 
  440. defined as a collection of items (type $dic\_item$) where each item contains 
  441. a pair in $K\times I$. We use \<$k,i$\> to denote an item with key $k$ and 
  442. information $i$ and require that for each $k\in K$ there is at most one 
  443. $i\in I$ such that \<$k,i$\> is in the dictionary. In mathematical terms this
  444. definition may be rephrased as follows: A dictionary $d$ is a partial
  445. function from the set $dic\_item$ to the set $K\times I$. Moreover, for each
  446. $k\in K$ there is at most one $i\in I$ such that the pair $(k,i)$ is in $d$.
  447.  
  448. The functionality of the operations 
  449. \smallskip
  450. \cleartabs
  451. \+\quad\quad &$dic\_item$ &$D$.lookup($K\ k$)\cr
  452. \+           &$I$         &$D$.inf($dic\_item\ it$)\cr
  453. \+           &$void$      &$D$.change\_inf($dic\_item\ it,\ I\ i\'$)\cr
  454. is now as follows:
  455. $D$.lookup($k$) returns an item $it$ with contents $(k,i)$, $D$.inf($it$) 
  456. extracts $i$ from $it$, and a new value $i\'$ can be associated with $k$ by
  457. $D$.change\_inf($it,i\'$).
  458.  
  459.  
  460. Let us have a look at the insert operation for dictionaries next:
  461. \smallskip
  462. \+&$dic\_item$ &$D$.insert($K\ k,\ I\ i$)\cr
  463.  
  464. There are two cases to consider. If $D$ contains an item $it$ with contents
  465. $(k,i\')$ then $i\'$ is replaced by $i$ and $it$ is returned. If $D$ contains
  466. no such item, then a new item, i.e., an item which is not contained in any 
  467. dictionary, is added to $D$, this item is made to contain $(k,i)$ and is
  468. returned. In this manual (cf.~section 4.3) all of this is abbreviated to
  469.  
  470. \smallskip
  471. \+&\cleartabs
  472.    $dic\_item$\ \ \ $D$.insert($K\ k,\  I\ i$) \quad 
  473.                          &associates the information $i$ with the key $k$.\cr
  474. \+&                      &If there is an item \<$k,j$\> in $D$ then $j$ is\cr
  475. \+&                      &replaced by i, else a new item \<$k,i$\> is added\cr
  476. \+&                      &to $D$. In both cases the item is returned.\cr
  477.  
  478.  
  479. We now turn to a general discussion. With some LEDA types $XYZ$ there is an
  480. associated type $XYZ\_item$ of items. Nothing is known about the objects of
  481. type $XYZ\_item$ except that there are infinitely many of them. The only
  482. operations available on $XYZ\_items$ besides the one defined in the
  483. specification of type $XYZ$ is the equality predicate ``=='' and the assignment
  484. operator ``='' . The objects of type $XYZ$ are defined as sets or sequences of
  485. $XYZ\_items$ containing objects of some other type $Z$. In this situation an
  486. $XYZ\_item$ containing an object $z\in Z$ is denoted by \<$z$\>. A new or unused
  487. $XYZ\_item$ is any $XYZ\_item$ which is not part of any object of type $XYZ$.
  488.  
  489. {\bf Remark}: For some readers it may be useful to interpret a $dic\_item$ as
  490. a pointer to a variable of type $K\times I$. The differences are that the
  491. assignment to the variable contained in a $dic\_item$ is restricted, e.g., the
  492. $K$-component cannot be changed, and that in return for this restriction the
  493. access to $dic\_items$ is more flexible than for ordinary variables, e.g.,
  494. access through the value of the $K$-component is possible.
  495.  
  496.  
  497. \bigskip
  498. \bigskip
  499. {\magonebf 1.8 Iteration}
  500.  
  501. For many data types LEDA provides iteration macros. These macros can be
  502. used to iterate over the elements of lists, sets and dictionaries or
  503. the nodes and edges of a graph. Iteration macros can be used similarly to 
  504. the \CC {\bf for} statement. Examples are
  505.  
  506. for all item based data types:
  507. \smallskip
  508. {\bf forall\_items}($it,D$) 
  509. $\{$ the items of $D$ are successively assigned to variable $it \}$
  510.  
  511. for lists and sets:
  512. \smallskip
  513. {\bf forall}($x,L$) $\{$ the elements of $L$ are successively assigned to $x \}$
  514.  
  515. for graphs:
  516. \smallskip
  517. {\bf forall\_nodes}($v,G$) $\{$ the nodes of $G$ are successively
  518. assigned to $v \}$
  519. \smallskip
  520. {\bf forall\_edges}($e,G$) $\{$ the edges of $G$ are successively
  521. assigned to $e \}$
  522. \smallskip
  523. {\bf forall\_adj\_edges}($e,v$) $\{$ all edges adjacent to $v$ are
  524. successively assigned to $e \}$
  525.  
  526.  
  527. \bigskip
  528. \bigskip
  529. {\magonebf 1.9 Header Files}
  530.  
  531. LEDA data types and algorithms can be used in any \CC program as described 
  532. in this manual. The specifications (class declarations) are contained
  533. in header files. To use a specific data type its header file has to be 
  534. included into the program. In general the header file for data type xyz is 
  535. \<LEDA/xyz.h\>. Exceptions to this rule are described in Table~10.1 and
  536. 10.2.
  537.  
  538.  
  539. \bigskip
  540. \bigskip
  541. {\magonebf 1.10 Libraries}
  542.  
  543. The implementions of all LEDA data types and algorithms are precompiled and 
  544. contained in 5 libraries (libL.a, libG.a, libP.a, libWs.a, libWx.a) 
  545. which can be linked with \CC application programs. In the following
  546. description it is assumed that these libraries are installed in one of the 
  547. systems default library directories (e.g. /usr/lib), which allows to use 
  548. the ``-l\dots'' compiler option.
  549.  
  550. \medskip
  551. a) {\bf libL.a}
  552. is the main LEDA library, it contains the implementations of all simple 
  553. data types (section~2), basic data types (section~3), dictionaries and priority
  554. queues (section~4). A program $prog.c$ using any of these data types has to be
  555. linked with the libL.a library like this:
  556.  
  557. CC $prog.c$ -lL
  558.  
  559.  
  560. \medskip
  561. b) {\bf libG.a}
  562. is the LEDA graph library. It contains the implementations of all graph 
  563. data types and algorithms (section~5). To compile a program using any graph 
  564. data type or algorithm the libG.a and libL.a library have to be used:
  565.  
  566. CC $prog.c$ -lG -lL
  567.  
  568.  
  569. \medskip
  570. c) {\bf libP.a}
  571. is the LEDA library for geometry in the plane. It contains the 
  572. implementations of all data types and algorithms for two-dimensional 
  573. geometry (section~6). To compile a program using two-dimensional data 
  574. types or algorithms the libP.a, libG.a, libL.a and maths libraries have 
  575. to be used:
  576.  
  577. CC $prog.c$ -lP -lG -lL -lm 
  578.  
  579. \medskip
  580. d) {\bf libWx11.a}, {\bf libWxview.a}
  581. are the LEDA libraries for graphic windows under the X11 or xview 
  582. window systems. Application programs using data type $window$ 
  583. (cf.~section~6.7) have to be linked with one of these libraries:
  584.  
  585. \beginitem
  586. \item{ a)} 
  587. For the X11 window system:\nl
  588. CC $prog.c$ -lP -lG -lL -lWx11 -lX11 -lm
  589.  
  590. \item{ b)} 
  591. For the xview window system:\nl
  592. CC $prog.c$ -lP -lG -lL -lWxview -lxview -lolgx -lX11 -lm
  593. \enditem
  594.  
  595. Note that the libraries must be given in the order -lP -lG -lL 
  596. and that the window library (-lWx11 or -lWxview) has to appear after the
  597. plane library (-lP).
  598.  
  599. \vfill\eject
  600.